package dk.itu.mario.level;

import java.util.Arrays;

import dk.itu.mario.MarioInterface.GamePlay;

public class Classify {

	public double complexity, coins, killerAggresivity, blocks, powerBlock = .2;
	public double totalKilled, armoredTurtle, greenTurtle, redTurtle, Goomba, jumpFlower, chompFlower, cannonBall, invisible;

	public double pipes = .01, cannons = .01, logs = .01;
	public double hills = .05, stools = .01;
	public double jumpProbability, floorDensity, flying = .01, eccentric = 0;

	public Classify(GamePlay game, int difficulty)
	{		
		
		totalKilled=game.ArmoredTurtlesKilled+game.GreenTurtlesKilled+game.RedTurtlesKilled+ game.GoombasKilled + game.JumpFlowersKilled + game.ChompFlowersKilled + game.CannonBallKilled;
		killerAggresivity= sigmoid(((double)totalKilled)/(game.totalEnemies+1));
		
		double f=1.6;
		armoredTurtle=sigmoid((((double)game.ArmoredTurtlesKilled)/(totalKilled+1))+killerAggresivity-f);
		greenTurtle=sigmoid((((double)game.GreenTurtlesKilled)/(totalKilled+1))+killerAggresivity-f);
		redTurtle=sigmoid((((double)game.RedTurtlesKilled)/(totalKilled+1))+killerAggresivity-f);
		Goomba=sigmoid((((double)game.GoombasKilled)/(totalKilled+1))+killerAggresivity-f);
		jumpFlower=sigmoid((((double)game.JumpFlowersKilled)/(totalKilled+1))+killerAggresivity-f);
		chompFlower=sigmoid((((double)game.ChompFlowersKilled)/(totalKilled+1))+killerAggresivity-f);
		cannonBall=sigmoid((((double)game.CannonBallKilled)/(totalKilled+1))+killerAggresivity-f);
		
		
		complexity=sigmoid(((double)game.completionTime-game.timeRunningRight)/game.completionTime + ((double)game.aimlessJumps)/game.totalTime-killerAggresivity/2);

		//complexity=.3;
		coins=sigmoid(((double)game.coinsCollected)/game.totalCoins-1.2);
		
		
		blocks= sigmoid(((double)(game.coinBlocksDestroyed+game.powerBlocksDestroyed+game.emptyBlocksDestroyed))/(game.totalpowerBlocks+game.totalEmptyBlocks+game.totalCoinBlocks)+complexity/2-1);
		
		
		
		
		floorDensity=(complexity*complexity)/5; //make complexity proportional to consistency of floor, divided by 5 is scaling-->how quickly floor changes 
		
		
		jumpProbability= sigmoid(-complexity+difficulty/20.0-game.timesOfDeathByFallingIntoGap-killerAggresivity);
//		if (killerAggresivity>.4 && jumpProbability>.4){
//			jumpProbability=.4;
//		}
		
		

		double additives=complexity*complexity/100;
		pipes=additives;
		cannons=killerAggresivity*killerAggresivity/100;
		stools=additives;
		logs=additives;
		hills=additives;

	}

	public Classify() {
		// TODO Auto-generated constructor stub
	}

	public void print(GamePlay game) {
		System.out.println("total time: " + game.totalTime);
		System.out.println("completion time: " + game.completionTime);
		System.out.println("time running left: " + game.timeRunningLeft);
		System.out.println("time running right: " + game.timeRunningRight);
		System.out.println("time running: " + game.timeSpentRunning);

		System.out.println("aimlessJumps: " + game.aimlessJumps);
		System.out.println("numjumps" + game.jumpsNumber);
		System.out.println("new Complexity" + complexity);
		System.out.println("complexity: " + complexity);
		System.out.println("coins: " + coins);
		System.out.println("blocks" + blocks);
		System.out.println("killerAggresivity:" + killerAggresivity);
		System.out.println("armored turtle: " + armoredTurtle);
		System.out.println("green turtle: " + greenTurtle);
		System.out.println("red turtle: " + redTurtle);
		System.out.println("goomba: " + Goomba);
		System.out.println("jump flower: " + jumpFlower);
		System.out.println("chomp flower: " + chompFlower);
		System.out.println("cannon ball: " + cannonBall);
		System.out.println("density: " + floorDensity);
		System.out.println("jump probability: " + jumpProbability);
	}

	public double sigmoid(double d) {
		return 1 / (1 + Math.exp(-4 * d + 2));
	}

	public double[] getProbability() {
		double[] prob = { complexity, coins, killerAggresivity, blocks, powerBlock, totalKilled, armoredTurtle, greenTurtle,
				redTurtle, Goomba, jumpFlower, chompFlower, cannonBall, invisible, pipes, cannons, logs, hills, stools, jumpProbability, floorDensity,
				flying, eccentric };
		return prob;
	}

	public void setProbability(double[] prob) {
		int i = 0;
		complexity = prob[i++];
		coins = prob[i++];
		killerAggresivity = prob[i++];
		blocks = prob[i++];
		powerBlock = prob[i++];
		totalKilled = prob[i++];
		armoredTurtle = prob[i++];
		greenTurtle = prob[i++];
		redTurtle = prob[i++];
		Goomba = prob[i++];
		jumpFlower = prob[i++];
		chompFlower = prob[i++];
		cannonBall = prob[i++];
		invisible = prob[i++];
		pipes = prob[i++];
		cannons = prob[i++];
		logs = prob[i++];
		hills = prob[i++];
		stools = prob[i++];
		jumpProbability = prob[i++];
		floorDensity = prob[i++];
		flying = prob[i++];
		eccentric = prob[i++];
	}

}
